package com.ruoyi.business.controller;

import java.util.List;

import com.ruoyi.common.core.domain.entity.SysUser;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.business.domain.CustomerLawyer;
import com.ruoyi.business.service.ICustomerLawyerService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * customerController
 * 
 * @author liwenjing
 * @date 2021-04-28
 */
@RestController
@RequestMapping("/business/customerlawyer")
public class CustomerLawyerController extends BaseController
{
    @Autowired
    private ICustomerLawyerService customerLawyerService;

    /**
     * 查询所有的律师
     * 新增时，用到律师选择框里面
     */
    @GetMapping("/alllawyer")
    public TableDataInfo allLawyer(){
        List<SysUser> list = customerLawyerService.selectAllLawyer();
        return getDataTable(list);
    }

    /**
     * 查询customer列表
     */
    @GetMapping("/list")
    public TableDataInfo list(CustomerLawyer customerLawyer)
    {
        startPage();
        List<CustomerLawyer> list = customerLawyerService.selectCustomerLawyerList(customerLawyer);
        return getDataTable(list);
    }

    /**
     * 导出customer列表
     */
    @PreAuthorize("@ss.hasPermi('business:CustomerLawyer:export')")
    @Log(title = "customer", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(CustomerLawyer customerLawyer)
    {
        List<CustomerLawyer> list = customerLawyerService.selectCustomerLawyerList(customerLawyer);
        ExcelUtil<CustomerLawyer> util = new ExcelUtil<CustomerLawyer>(CustomerLawyer.class);
        return util.exportExcel(list, "CustomerLawyer");
    }

    /**
     * 获取customer详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(customerLawyerService.selectCustomerLawyerById(id));
    }

    /**
     * 新增customer
     */
    @PreAuthorize("@ss.hasPermi('business:CustomerLawyer:add')")
    @Log(title = "customer", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CustomerLawyer customerLawyer)
    {
        return toAjax(customerLawyerService.insertCustomerLawyer(customerLawyer));
    }

    /**
     * 修改customer
     */
    @PreAuthorize("@ss.hasPermi('business:CustomerLawyer:edit')")
    @Log(title = "customer", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CustomerLawyer customerLawyer)
    {
        return toAjax(customerLawyerService.updateCustomerLawyer(customerLawyer));
    }

    /**
     * 删除customer
     */
    @PreAuthorize("@ss.hasPermi('business:CustomerLawyer:remove')")
    @Log(title = "customer", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(customerLawyerService.deleteCustomerLawyerByIds(ids));
    }
}
